package m202401.d02;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/2 08:54
 */
//242. 有效的字母异位词
public class Q242 {
    public boolean isAnagram(String s, String t) {
        int[] map = new int['z' - 'a' + 1];
        for (int i = 0; i < s.length(); i++) {
            map[s.charAt(i) - 'a'] += 1;
        }
        for (int i = 0; i < t.length(); i++) {
            int index = t.charAt(i) - 'a';
            map[index] -= 1;
            if (map[index] < 0) {
                return false;
            }
        }
        for (int i = 0; i < map.length; i++) {
            if (map[i] != 0) {
                return false;
            }
        }
        return true;
    }
}
